﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TileEditor
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private List<SolidColorBrush> colors;

        public Window1()
        {
            InitializeComponent();

            colors = new List<SolidColorBrush>();
            colors.Add(new SolidColorBrush(Colors.Tomato));
            colors.Add(new SolidColorBrush(Colors.Peru));
            colors.Add(new SolidColorBrush(Colors.DarkGoldenrod));
            colors.Add(new SolidColorBrush(Colors.DarkGray));
            colors.Add(new SolidColorBrush(Colors.Azure));
            colors.Add(new SolidColorBrush(Colors.BurlyWood));
            colors.Add(new SolidColorBrush(Colors.Wheat));
            colors.Add(new SolidColorBrush(Colors.LightGray));
            colors.Add(new SolidColorBrush(Colors.LightYellow));
            colors.Add(new SolidColorBrush(Colors.DarkGreen));
            colors.Add(new SolidColorBrush(Colors.DarkKhaki));
            colors.Add(new SolidColorBrush(Colors.Blue));
            colors.Add(new SolidColorBrush(Colors.BlanchedAlmond));
            colors.Add(new SolidColorBrush(Colors.LemonChiffon));
            colors.Add(new SolidColorBrush(Colors.SeaShell));
            colors.Add(new SolidColorBrush(Colors.SeaGreen));
            colors.Add(new SolidColorBrush(Colors.Black));
            colors.Add(new SolidColorBrush(Colors.Ivory));

            ColorSelector.ItemsSource = colors;

            // initally set the grid to 10x10
            testGrid.Rows = 10;
            testGrid.Cols = 10;
        }

        #region Commands

        private void ExitCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void ExitCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            this.Close();
        }



        private void NewCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void NewCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (MessageBox.Show("Discard changes?",
                        "New map...",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Question,
                        MessageBoxResult.Yes) == MessageBoxResult.Yes)
            {
                // nothing yet
            }
        }

        private void SaveCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void SaveCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {

        }

        private void ClearMap_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void ChangeMapSize_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void ClearMap_Executed(object sender, ExecutedRoutedEventArgs e)
        {

        }

        private void ChangeMapSize_Executed(object sender, ExecutedRoutedEventArgs e)
        {

        }


        #endregion

        private void ColCount_TextChanged(object sender, TextChangedEventArgs e)
        {
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            // todo: Refactor. we should probably send the to the dialog 
            // so it can manipulate it directly! or even better... use databinding :P

            ChangeMapOptions op = new ChangeMapOptions();
            op.Brush = testGrid.PointerSize;
            op.Width = testGrid.Width;
            op.Height = testGrid.Height;

            op.ShowDialog();
            if (op.Save)
            {
                testGrid.Rows = op.Rows;
                testGrid.Cols = op.Cols;
                testGrid.PointerSize = op.Brush;
                op.Close();
            }
        }
    }
}
